from flask_migrate import Migrate


from applications.extensions import db
from applications.__init__app import create_app
from applications.extensions import init_plugs
from flask_cors import *
from apscheduler.schedulers.background import BackgroundScheduler

from applications.models.borrow_info import suspend_licence, resume_licence

app = create_app()

migrate = Migrate(app, db)

CORS(app, supports_credentials=True, resources={"/*": {"origins": "http://localhost:8080"}})

# 注册各种插件
init_plugs(app)

if __name__ == '__main__':
    # 创建一个后台调度器
    scheduler = BackgroundScheduler()
    # 添加定时任务
    scheduler.add_job(suspend_licence, 'interval', hours=24)  # 每隔24小时执行一次 suspend_licence 函数
    # 在启动定时任务的地方添加 resume_licence 函数
    scheduler.add_job(resume_licence, 'interval', hours=24)
    # 启动调度器
    scheduler.start()
    app.run()